package com.qying.sort;

/**
 * 插入排序
 */
public class InsertSort {

    public static void main(String[] args) {
        int[] arr = Number.arr;

        for (int i : arr) {
            System.out.print(i + ",");
        }
        System.out.println();

        for (int i = 0; i < arr.length -1; i++) {
            int cur = arr[i +1];
            int preIndex = i;
            while (preIndex >=0 && arr[preIndex] > cur) {
                arr[preIndex +1] = arr[preIndex];
                preIndex --;
            }
            arr[preIndex+1] = cur;
        }


        for (int i : arr) {
            System.out.print(i + ",");
        }
    }
}
